package com.share.user.api;

import com.share.common.core.domain.R;
import com.share.common.core.web.controller.BaseController;
import com.share.common.security.annotation.InnerAuth;
import com.share.user.api.domain.UpdateUserLogin;
import com.share.user.api.domain.UserInfo;
import com.share.user.service.IUserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/10/17 下午6:35
 */
@Tag(name = "用户远程调用接口")
@RestController
@RequestMapping("/userInfo")
@RequiredArgsConstructor
public class UserInfoApiController extends BaseController {

    private final IUserInfoService userInfoService;

    /**
     * 小程序收取登录
     *
     * @param code
     * @return
     */
    @Operation(summary = "小程序授权登录")
//    @InnerAuth
    @GetMapping("/wxLogin/{code}")
    public R<UserInfo> wxLogin(@PathVariable String code) {
        return R.ok(userInfoService.wxLogin(code));
    }

    @Operation(summary = "更新用户登录信息")
//    @InnerAuth
    @PutMapping("/updateUserLogin")
    public R<Boolean> updateUserLogin(@RequestBody UpdateUserLogin updateUserLogin) {
        return R.ok(userInfoService.updateUserLogin(updateUserLogin));
    }

    @Operation(summary = "获取用户信息")
    @GetMapping("/getUserInfo/{userId}")
    public R<UserInfo> getUserInfo(@PathVariable Long userId) {
        return R.ok(userInfoService.getById(userId));
    }

    //统计2024年每个月注册人数
    //远程调用：统计用户注册数据
    @GetMapping("/getUserCount")
    public R<Map<String,Object>> getUserCount(){
      Map<String,Object> map = userInfoService.getUserCount();
        return R.ok(map);
    }
}
